var user = null;

function checkLogin(){
    console.log("checking login")
    $.post({
        url: 'http://localhost:8080/login/checkLogin',
        async:false,
        method: 'POST',
        crossDomain: true,
        xhrFields: { withCredentials: true },
        success: function (msg) {
            let user = msg.data.user;
            //    user是
            if(user == null){
                layer.msg("请登录");
                window.location.href='../home.html';
            }
            window.user = user;
        }, error: function (error) {
            console.log(error)
        }
    })
}


function loadData(){
    //loadIframe src
        //loadUserInfo
    checkLogin();
        //load Iframe src
    $("#friendTab").attr("src","./friend.html?id="+user.base.id)
    $("#srchTab").attr("src","./srch.html?id="+user.base.id)
    $("#requestTab").attr("src","./request.html?id="+user.base.id)
}
function switchTab(tabId){
    //switch tab
    let $tab = $(".tab");
    $tab.each((i,e)=>{
        console.log(e)
        $(e).removeClass("tab-this");
    });
    let $thisTab = $(tabId);
    $thisTab.addClass("tab-this");
    //showIframe
    $("#main-iframe").attr("src",$thisTab.attr("src"));
}